-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Added the ability to filter the corresponding files based on the access_time, modify time, and change time of the file for statistics. #399
Conversation
Apologies I've had a laptop failure. Don't want to risk looking at this on my work laptop for legal reasons. Will review this when I get a new machine. |
completions/_dust
Outdated
@@ -37,6 +37,12 @@ _dust() { | |||
'--output-format=[Changes output display size. si will print sizes in powers of 1000. b k m g t kb mb gb tb will print the whole tree in that size.]:FORMAT:(si b k m g t kb mb gb tb)' \ | |||
'-S+[Specify memory to use as stack size - use if you see\: '\''fatal runtime error\: stack overflow'\'' (default low memory=1048576, high memory=1073741824)]:STACK_SIZE: ' \ | |||
'--stack-size=[Specify memory to use as stack size - use if you see\: '\''fatal runtime error\: stack overflow'\'' (default low memory=1048576, high memory=1073741824)]:STACK_SIZE: ' \ | |||
'-M+[File'\''s data was last modified less than, more than or exactly <mtime>*24 hours ago. When dust figures out how many 24-hour periods ago the file was last modified, any fractional part is ignored, so to match -mtime +1, a file has to have been modified at least two days ago.]: : ' \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider making the description more easily readable
'-M+[File'\''s data was last modified less than, more than or exactly <mtime>*24 hours ago. When dust figures out how many 24-hour periods ago the file was last modified, any fractional part is ignored, so to match -mtime +1, a file has to have been modified at least two days ago.]: : ' \ | |
'-M+[Sort by time modifed, include only files modified +/-<mtime> days before/after, days are rounded down, prefix \'\-\' for newer, \'\+\' for older. : : ' \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, Filter by time mofied is better than Sort by time modifed because this parameter is used for filtering, not sorting. right? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, you can rephrase it as you wish, just pointed that its a bit too long :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, that description is a bit too long. I rephrased it . I will be very happy if you can help me review the code again. :)
src/dir_walker.rs
Outdated
@@ -167,6 +191,9 @@ fn walk(dir: PathBuf, walk_data: &WalkData, depth: usize) -> Option<Node> { | |||
data.is_file(), | |||
walk_data.by_filecount, | |||
depth, | |||
filter_modified_time, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider changing build_node
to accept a walk_data
argument instead of individually 7 of walk_data
's fields
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, you are right, I reorganized the code according to your ideas. I will be very happy if you can help me review the code again. :)
You are always one click away from a GitHub Codespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like a good idea. I like it! I'll try it. :) |
I've been thinking seriously about this over the past few days. If we modify the tool according to your approach, we'll need to add a parameter to set the upper and lower limits of the filter time. Otherwise, the scenario for equal values would no longer exist. While this method provides great flexibility, I'm concerned about whether such a high level of flexibility is necessary for this tool. Adding this feature might place a significant cognitive burden on the users. After all, people are probably accustomed to using the find command with the -mtime option, which filters by days, or the -mmin option, which filters by minutes. What are your thoughts on this? @bootandy |
Just incase you are running on a very small folder. Some people seem to use dust as a sort of file-finder so I want to include them. |
[CompletionResult]::new('-A', 'A ', [CompletionResultType]::ParameterName, 'just like -mtime, but based on file access time') | ||
[CompletionResult]::new('--atime', 'atime', [CompletionResultType]::ParameterName, 'just like -mtime, but based on file access time') | ||
[CompletionResult]::new('-y', 'y', [CompletionResultType]::ParameterName, 'just like -mtime, but based on file change time') | ||
[CompletionResult]::new('--ctime', 'ctime', [CompletionResultType]::ParameterName, 'just like -mtime, but based on file change time') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we need all these - I like the idea of a including a filter that works with modified time. But 'access time' - would someone actually use that? I have to launch 'stat' to even see it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah we can leave it in if you'd like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, access time is an effective filtering tool when users want to determine whether a file has been accessed recently based on the access time to determine whether other people are using the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that you based the parameters for this work from find.
We seem to have a few cargo style problems. But overall I think this approach is correct.
src/dir_walker.rs
Outdated
depth, | ||
walk_data, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sensible change, there were too many params.
Yes, you are right! :) |
I'm fairly new to Rust , so my coding style may not be very good. If there is anything that needs to be modified, I hope you will give me some advice. thx! |
Your coding style looks fine to me. The build however gave style errors ^ see the red 'X's in the build. On your cmd line: Run 'cargo fmt' - this neatens things automatically Run 'cargo clippy' - this is a linter which will suggest fixes and warns of likely bugs, so you'll have to review each one. you can see the list of errors from the online build here: https://github.com/bootandy/dust/actions/runs/9461768640/job/26334984807?pr=399 |
0f6e035
to
98e26ba
Compare
Thank you for your guidance in helping me improve my code to meet the standards. I have resubmitted it, and all checks have passed. :) |
I don't have strong opinions on this. But lets stabilise -mtime an -mmin for now. If we want to do the more flexible one we can do that in a followup. It definitely shouldn't go in this PR. |
Would you mind doing a rebase or merge - I've accepted a different PR and there are some conflicts ^ - thanks . |
Indeed, I agree with you. :) |
Ok. I'm happy to do it! :) |
…e access time, modify time, and change time of the file for statistics
use crate::display::get_number_format; | ||
|
||
pub static DAY_SECEONDS: i64 = 24 * 60 * 60; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, due to my carelessness, I did not correct this spelling error in time. I will resubmit a PR for processing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a problem! we all do it.
Background
Filter by file age #340
Add a new feature to dust to filter files based on their last update time, last access time, and last modification time.
In order to achieve this requirement, I referred to the input of the linux find command, and ultimately planned to implement the dust filter by file age function based on the input style of find.
I have a little question here, why does dust output files or directories with a file size of 0 by default? The dust tool is used to quickly find those files and directories in the specified directory that take up too much space, and those empty files or directories will only affect the look and feel. Originally, I have implemented filtering out those files or directories with a size of 0, but when I run cargo test When running the test, I found that some samples reported errors, so I canceled this part of the code, but I still wanted to retain the function of filtering out those files or directories with a size of 0. I hope this function can be further explored. thanks
Full Changelogs
Issue Reference
fix: Filter by file age #340
Test Result
dust help command output

Test Data
cargo test run test results
Adding --mtime or --atime or --ctime results in actual execution of dust and linux find with similar parameters.